package com.zch.research.mqtt.provider.controller;

import com.zch.client.spring.mqtt.client.FastMqttClient;
import com.zch.client.spring.mqtt.dto.MqttSendRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
public class SendController {
    @Resource
    FastMqttClient fastMqttClient;

    @PostMapping("/sendMessage")
    @ResponseBody
    public String sendMessage(@RequestBody MqttSendRequest mqttRequest){
        try {
            fastMqttClient.send(mqttRequest);
            return "发送成功";
        } catch (Exception e) {
            e.printStackTrace();
            return "发送失败";
        }
    }

}
